#!/usr/bin/python
from optparse import OptionParser



def main():
  parser = OptionParser()
  
  parser.add_option('--num1', action='store', type='float', dest='num1')
  parser.add_option('--num2', action='store', type='float', dest='num2')
  parser.add_option('--operation' , action='store', type='string',dest='operation')
  (options, _) = parser.parse_args()  
  #Calculate(options)

  result = Calculate(options)


  print result 

  #print 'num1=', options.num1 
  #print 'num2=', options.num2 
  #print 'operation=', options.operation 
  
def Calculate(opt):
  if opt.operation == 'add':      
    result = Add(opt.num1, opt.num2)
  if opt.operation == 'subtract':
    result = Subtract(opt.num1, opt.num2)
  if opt.operation == 'multiply':
    result = Multiply(opt.num1, opt.num2)
  if opt.operation == 'divide':
    result = Divide(opt.num1, opt.num2)
  return result
  
def Add(cislo1, cislo2):
  #print '%r' % cislo1
  #print '%r' % cislo2

  for x in [cislo1, cislo2]:
    if not isinstance(x, (float, int, long)):
      raise ValueError('invalid input')
  return cislo1 + cislo2


def Subtract(cislo1, cislo2):
  for x in [cislo1, cislo2]:
    if not isinstance(x, (float, int, long)):
      raise ValueError('invalid input')
  return cislo1 - cislo2

def Multiply(cislo1, cislo2):
  for x in [cislo1, cislo2]:
    if not isinstance(x, (float, int, long)):
      raise ValueError('invalid input')
  return cislo1 * cislo2

def Divide(cislo1, cislo2):
  for x in [cislo1, cislo2]:
    if not isinstance(x, (float, int, long)):
      raise ValueError('invalid input')
  return cislo1 / cislo2

if __name__ == '__main__':
  main()






